package com.guaju.yueshangLife.widget.mine;

import android.app.Activity;
import android.content.Context;
import android.content.res.TypedArray;
import android.databinding.DataBindingUtil;
import android.text.TextUtils;
import android.util.AttributeSet;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.FrameLayout;
import android.widget.TextView;

import com.guaju.yueshangLife.R;
import com.guaju.yueshangLife.databinding.OrderTopBinding;

public class TopBarWrite extends FrameLayout {

    private LayoutInflater layoutInflater;
    private OrderTopBinding binding;

    public TopBarWrite(Context context) {
        super(context);
        init();
    }

    public TopBarWrite(Context context, AttributeSet attrs) {
        super(context, attrs);
        init();
        TypedArray ta = context.obtainStyledAttributes(attrs, R.styleable.topbar);
        String bartitle = ta.getString(R.styleable.topbar_bartitle);
        String righttext = ta.getString(R.styleable.topbar_righttext);
        int color = ta.getColor(R.styleable.topbar_righttextcolor, getResources().getColor(R.color.grey_333));
        binding.tvTitle.setText(bartitle);
        if (TextUtils.isEmpty(righttext)){
            binding.tvRight.setVisibility(View.GONE);
        }else{
            binding.tvRight.setVisibility(View.VISIBLE);
            binding.tvRight.setTextColor(color);
            binding.tvRight.setText(righttext);
        }

    }

    private void init() {
        layoutInflater = LayoutInflater.from(getContext());
        binding = DataBindingUtil.inflate(layoutInflater, R.layout.order_top,this,false);
        binding.flBack.setOnClickListener(new OnClickListener() {
            @Override
            public void onClick(View v) {
                ((Activity)getContext()).finish();
            }
        });
        addView(binding.getRoot());
    }
    public TextView getRightText() {
        return binding.tvRight;
    }
    public FrameLayout getLeftBack(){
        return binding.flBack;
    }

}
